//-----------------------------------------------------------------------
// <copyright file="PresentDAO.cs" company="Pyramid Consulting">
//     Copyright (c) Pyramid Consulting. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
	
using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using Microsoft.Practices.EnterpriseLibrary.Data;
using BirthdayReminder.Entities;

using Pyco;
using Pyco.Diagnostics;
using Pyco.Data;


namespace BirthdayReminder.Data
{	
	public class PresentDAO : PresentDAOBase
	{
		public PresentDAO()
		{
		}

        public TotalNumberPresentCollection GetTotalNumberPresentList(string receiverIDList)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("spPresentsGetTotalNumberList");

                database.AddInParameter(dbCommand, "@ReceiverIdList", DbType.AnsiString, receiverIDList);

                TotalNumberPresentCollection totalNumberPresents = new TotalNumberPresentCollection();
                using (IDataReader reader = DataAccessHelper.ExecuteReader(database, dbCommand))
                {
                    while (reader.Read())
                    {
                        TotalNumberPresent totalNumberPresent = new TotalNumberPresent();
                        if (!reader.IsDBNull(reader.GetOrdinal("TotalNumber"))) totalNumberPresent.TotalNumber = (int)reader["TotalNumber"];
                        if (!reader.IsDBNull(reader.GetOrdinal("ReceiverId"))) totalNumberPresent.ReceiverID = (int)reader["ReceiverId"];
                        totalNumberPresents.Add(totalNumberPresent);
                    }
                    reader.Close();
                }
                return totalNumberPresents;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new DataAccessException(ex.Message);
            }
        }
	}
}